<?php

use Beike\Seller\Models\SellerUser;
use Beike\Seller\Repositories\SellerRepo;

/**
 * 获取商户当前登录用户
 *
 * @return mixed
 */
function current_seller_user(): ?SellerUser
{
    return auth()->guard(SellerUser::AUTH_GUARD)->user();
}

/**
 * 获取前台链接
 *
 * @param $route
 * @param mixed $params
 * @return string
 */
function seller_route($route, $params = []): string
{
    return route('seller.' . $route, $params);
}

/**
 * 通过商户ID获取商户的店铺名称
 * @param $sellerId
 * @return string
 */
function seller_store_name($sellerId): string
{
    return SellerRepo::mapIdToStoreName()[$sellerId] ?? '';
}

/**
 * 判断商品是不是已经审核
 * @param $productId
 * @return bool
 */
function need_approve($productId): bool
{
    $product = \Beike\Models\Product::query()->find($productId);
    if (! $product) {
        return false;
    }
    if ($product->seller_id == 0) {
        return false;
    }
    if ($product->approved_at) {
        return false;
    }

    return true;
}

function default_weight_class(): string
{
    return \Beike\Libraries\Weight::DEFAULT_CLASS;
}

function is_seller(): bool
{
    $uri       = request()->getRequestUri();
    if (Str::startsWith($uri, '/seller')) {
        return true;
    }

    return false;
}
